import React, {useEffect} from "react";
import { Form, Input } from "antd";

import prompt from "vendor/utils/prompt";
import { WrappedComponentProps } from 'vendor/components/pro-hoc/withModal';


interface InitAdminProps extends WrappedComponentProps{
    accountId: string;
}

const InitAdmin: React.FC<InitAdminProps> = (props) => {
    const { form } = useInitAdmin(props);

    return <Form
        form={form}
        labelCol={{span: 5}}
        wrapperCol={{span: 15}}
    >
        <Form.Item label="用户名" name="userName">
            <Input />
        </Form.Item>
    </Form>
}

export default InitAdmin;

const useInitAdmin = (props: InitAdminProps) => {
    const { modalControl, accountId } = props;
    const [ form ] = Form.useForm();

    useEffect(() => {
        modalControl.registerOk(handleSubmit)
    })

    const handleSubmit = () => {
        form.validateFields().then((values) => {
            prompt.success("操作成功!");
            modalControl.close();
        }).catch(() => modalControl.hideSaving());
    }

    return { form }
}